#!/usr/bin/env python
# -*- coding: cp936 -*-
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import cgi
import datetime
import wsgiref.handlers
import os
from google.appengine.ext.webapp import template
from google.appengine.ext import db
from google.appengine.api import users
from google.appengine.ext import webapp


class MainPage(webapp.RequestHandler):
  def get(self):
    self.response.headers['Content-Type'] = 'text/html;charset=gbk'
    template_values = {
      }
    path = os.path.join(os.path.dirname(__file__), '../index.html')
    self.response.out.write(template.render(path, template_values))
    
class GoogleGadget(webapp.RequestHandler):
  def get(self):
    self.response.headers['Content-Type'] = 'text/html;charset=utf-8'
    if self.request.get('gadgetId') == "trans":
        self.response.out.write("<script src='http://www.gmodules.com/ig/ifr?url=http://www.google.com/ig/modules/dictionary.xml&amp;up_sl=en&amp;up_tl=zh-CN&amp;up_default_text=&amp;synd=open&amp;w=320&amp;h=200&amp;title=&amp;lang=zh-CN&amp;country=ALL&amp;border=%23ffffff%7C3px%2C1px+solid+%23999999&amp;output=js'></script>")
    if self.request.get('gadgetId') == "vedio":
        self.response.out.write("<script src='http://www.gmodules.com/ig/ifr?url=http://www.google.com/ig/modules/china/videocn.xml&amp;up_oneboxQuery=&amp;up_activeTabs=cat%3A169%7Ccat%3A111%7Ccat%3A107%7Ccat%3A126%7Ccat%3A109%7Ccat%3A113&amp;synd=open&amp;w=320&amp;h=350&amp;title=&amp;lang=zh-CN&amp;country=ALL&amp;border=%23ffffff%7C3px%2C1px+solid+%23999999&amp;output=js'></script>")
    if self.request.get('gadgetId') == "hotColumns":
        self.response.out.write("<script src='http://www.gmodules.com/ig/ifr?url=http://www.google.com/ig/modules/china/billboard.xml&amp;up_selectedTab=0&amp;up_last_billboard_id=12000000&amp;synd=open&amp;w=320&amp;h=200&amp;title=&amp;lang=zh-CN&amp;country=ALL&amp;border=%23ffffff%7C3px%2C1px+solid+%23999999&amp;output=js'></script>")
       
class MapTest(webapp.RequestHandler):
  def get(self):
    self.response.headers['Content-Type'] = 'text/html;charset=gbk'
    template_values = {
      }
    path = os.path.join(os.path.dirname(__file__), '../mapTest.html')
    self.response.out.write(template.render(path, template_values))


application = webapp.WSGIApplication([
  ('/', MainPage),
  ('/googleGadget.do', GoogleGadget),
  ('/mapTest.do', MapTest)
], debug=True)


def main():
  wsgiref.handlers.CGIHandler().run(application)


if __name__ == '__main__':
  main()
